package com.xie.system.infrastructure.converter;



import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xie.system.domain.message.messagerecord.MsgTypeEnum;
import com.xie.system.domain.message.messagerecord.NoticeType;
import com.xie.system.domain.template.selectdict.DictType;
import com.xie.system.domain.template.templateitem.InputType;

import java.util.Map;


/**
 * 枚举自定义转化 在实体类中的枚举都要进行配置
 */
public class CustomMapper {

  public Integer type2Int(InputType type) {
    return type.getCode();
  }

  public InputType int2Type(Integer code) {
    return InputType.of(code).orElse(InputType.TEXT);
  }

  public Integer dictType2Int(DictType dictType) {
    return dictType.getCode();
  }

  public DictType int2DictType(Integer code) {
    return DictType.of(code).orElse(DictType.SELECT_LIST);
  }

  public NoticeType int2NoticeType(Integer code){
    return NoticeType.of(code).orElse(null);
  }

  public Integer noticeType2Int(NoticeType noticeType){
    return noticeType.getCode();
  }

  public MsgTypeEnum int2MsgTypeEnum(Integer code){
    return MsgTypeEnum.of(code).orElse(null);
  }

  public Integer msgTypeEnum2Int(MsgTypeEnum msgTypeEnum){
    return msgTypeEnum.getCode();
  }

  public Map<String,Object> string2Map(String str){
    JSONObject jsonObject = JSONObject.parseObject(str);
    return jsonObject;
  }

  public String map2String(Map<String,Object> map){
    return JSON.toJSONString(map);
  }

}
